package com.gcxy.controller;


import com.gcxy.dto.Dic.DicPageDto;
import com.gcxy.dto.Dic.InsertDto;
import com.gcxy.service.DicService;
import com.gcxy.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wlp
 * @since 2023-12-19
 */
@RestController
@RequestMapping("/dic")
@Api(tags = "数据字典管理")
public class DicController {
    @Autowired
    private DicService dicService;
    private Logger logger= LoggerFactory.getLogger(getClass());
    @ApiOperation("字典新增")
    @PostMapping("insert")
    public R addDic(@Valid @RequestBody InsertDto requestBody){
        logger.info("正在字典新增");
        R result=dicService.addDic(requestBody);
        return result;
    }

    @ApiOperation("获取所有字典的值")
    @GetMapping("getAll")
    public R getAll(){
        logger.info("正在字典获取");
        R result=dicService.getAll();
        return result;
    }
    @ApiOperation("分页查询数据字典")
    @PostMapping ("page")
    public R pageDic(@RequestBody DicPageDto requestBody){
        logger.info("正在字典分页");
        R result=dicService.pageDic(requestBody);
        return result;
    }
    @ApiOperation("修改状态")
    @PutMapping("updateState/{dicId}/{dicState}")
    public R updateState(@PathVariable Integer dicId,@PathVariable Integer dicState){
        logger.info("正在字典修改状态");
        R result=dicService.updateState(dicId,dicState);
        return result;
    }
}

